{extend name="public/common"}
{block name="style"}
<link rel="stylesheet" href="__HOME__/css/common/mui.min.css">
<link rel="stylesheet" href="__HOME__/css/journal/detail.css">
<style>
    .viewer-button{
        width: 79px!important;
    }
    .work-descri div{
        margin-top: 0!important;
    }
    .imgs img{
        height: 200px!important;
        width:90vw!important;
    }
    .but{
        text-align: center;
    }
    .but span{
        display: inline-block;
        background: #09a536;
        color: #fff;
        font-size: 1.5rem;
        font-family: "微软雅黑";
        width:25.2vw;
        height:3rem;
        line-height:3rem;
        text-align: center;
        border-radius: 5px;
    }
    .loading {
        background: url("__HOME__/images/common/loading.png") center no-repeat;
        background-size: 10.8vw 10.8vw;
        position: fixed;
        left: 50%;
        top: 50%;
        z-index: 101;
        width: 10.8vw;
        height: 10.8vw;
        margin-left: -5.4vw;
        margin-top: -5.4vw;
        animation: rotate 2s ease infinite;
        display: none;
    }
    .closed{
        display: inline-block;
        background: url("__HOME__/images/common/close.png");
        width: 6vw;
        height: 6vw;
        background-size: 6vw 6vw;
        z-index: 999;
        margin-left: -4vw;
        margin-top: -8vw;
    }
</style>
{/block}
{block name="body"}
<div class="personal-intro">
    <div class="intro">
    <img src="{$msg.header}">
    <p class="name">{$msg.name}</p>
    <p class="position">{$msg.xuexiao}</p>
        {eq name="is" value="0"}
        <span class="closed"></span>
        {/eq}
    </div>
    <p class="time">发布时间：{$msg.time}</p>
</div>
<div class="line"></div>
<div class="work-descri">
    <span class="span">总结内容</span>
    <div class="imgs" style="padding-top: 20px">{$msg.content}</div>
</div>
{if condition="$is eq 0 and $msg.result neq ''"}
<div class="work-descri">
    <span class="span">老师批语</span>
    <div class="imgs" style="padding-top: 20px">{$msg.result}</div>
</div>
{/if}
{if condition="$is eq 1"}
<div class="work-descri">
    <span class="span">老师批语</span>
    <div style="padding-top: 20px">
        <textarea style="font-size: 1.5rem" placeholder="请输入批语..." name="result" rows="8">{$msg.result}</textarea>
        <div class="but">
            <span>提交</span>
        </div>
    </div>
</div>
{/if}
<div class="loading"></div>
{/block}
{block name="script"}
<script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
    //关闭分享
    function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    }
    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
    localStorage.setItem("state","1");
    $('title').text('点对点教育VIP学员_学习总结');
    $(".imgs img").on('click',function(event) {
        var imgArray = [];
        var curImageSrc = window.location.protocol+'//'+window.location.host+$(this).attr('src');
        var oParent = $(this).parent();
        if (curImageSrc && !oParent.attr('href')) {
            oParent.parent().find("img").each(function(index, el) {
                var itemSrc = window.location.protocol+'//'+window.location.host+$(this).attr('src');
                imgArray.push(itemSrc);
            });
            wx.previewImage({
                current: curImageSrc,
                urls: imgArray
            });
        }
    });
    var layout = function(){
        $('.imgs img' ).each(function(){
            var this_ = $(this);
            var n_img = this_.length;
            if(n_img == 4){
                this_.eq(1).after('<br>')
            }
        })
    };
    var imgresize = function (){
        $('.imgs img' ).each(function(){
                if($(this).width() == $(this).height()){
                    $(this).height('78px');
                    $(this).width('78px');
                }else if($(this).width() > $(this).height()){
                    $(this).height('78px' ).css({'left':-$(this).width()/2+78/2});
                }else{
                    $(this).width('78px').css({'top':-$(this).height()/2+78/2});
                }
            });
    };
    layout();
    imgresize();
    $(".but").click(function() {
        var result = $("textarea[name='result']").val();
        result = utf16toEntities(result);
        if (result == '' || result == null) {
            swal({
                title: ' ',
                text: '输入评语才可以提交哦~',
                type: 'error',
                allowOutsideClick :false,
                confirmButtonText: '确定'
            });
            return false;
        }
        var id = "{$msg.id}";
        $.ajax({
            type: "post",
            url: "{:Url('Journal/sign')}",
            data: {
                result: result,
                id:id
            },
            beforeSend: function (XMLHttpRequest) {
                $(".loading").show();
            },
            success: function (data) {
                $(".loading").hide();
                if (data.code == 1) {
                    swal({
                        title: ' ',
                        text: '提交成功',
                        type: 'success',
                        confirmButtonText: '确定',
                        allowOutsideClick :false,
                        timer: 1500
                    },function(){
                        window.location.reload();
                    });
                } else {
                    swal({
                        title: ' ',
                        text: '提交失败，请重试',
                        allowOutsideClick :false,
                        type: 'error',
                        confirmButtonText: '确定',
                        timer: 1500
                    })
                }
            }
        })

    });
    $(".closed").click(function() {
        swal({
            title: "",
            text:"确定删除吗？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function() {
            var id = "{$msg.id}";
            $.ajax({
                type: "post",
                url: "{:Url('Journal/dele')}",
                data: {
                    id: id
                },
                beforeSend: function (XMLHttpRequest) {
                    $(".loading").show();
                },
                success: function (data) {
                    $(".loading").hide();
                    if (data.code == 1) {
                        swal({
                            title: ' ',
                            text: '删除成功',
                            type: 'success',
                            confirmButtonText: '确定',
                            allowOutsideClick: false,
                            timer: 1500
                        }, function () {
                            window.history.go(-1);
                        });
                    } else {
                        swal({
                            title: ' ',
                            text: '删除失败，请重试',
                            allowOutsideClick: false,
                            type: 'error',
                            confirmButtonText: '确定',
                            timer: 1500
                        })
                    }
                }
            });
        });
    });
    /**
     * 用于把用utf16编码的字符转换成实体字符，以供后台存储
     * @param  {string} str 将要转换的字符串，其中含有utf16字符将被自动检出
     * @return {string}     转换后的字符串，utf16字符将被转换成&#xxxx;形式的实体字符
     */
    function utf16toEntities(str) {
        var patt=/[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则
        str = str.replace(patt, function(char){
            var H, L, code;
            if (char.length===2) {
                H = char.charCodeAt(0); // 取出高位
                L = char.charCodeAt(1); // 取出低位
                code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; // 转换算法
                return "&#" + code + ";";
            } else {
                return char;
            }
        });
        return str;
    }
</script>

{/block}